/* 
 * File:   PIC18_I2C.h
 * Author: Administrator
 *
 * Created on 2014年4月2日, 下午4:07
 */

#ifndef PIC18_I2C_H
#define	PIC18_I2C_H

#ifdef	__cplusplus
extern "C" {
#endif

#define I2CMASTERMODE 0
#define I2CSLAVEMODE  1

#define I2C1RELASESCL   SSP1CON1bits.CKP = 1;        // release clock line

#define I2C1Start   SSP1CON2bits.SEN = 1;            // initiate bus start condition
#define I2C1Restart SSP1CON2bits.RSEN = 1;           // initiate bus restart condition
#define I2C1Stop    SSP1CON2bits.PEN = 1;            // initiate bus stop condition
#define I2C1Close   SSP1CON1bits.SSPEN = 0;
#define I2C1Ack     {                                \
                        SSP1CON2bits.ACKDT = 0;      \
                        SSP1CON2bits.ACKEN = 1;      \
                    }
#define I2C1Idle    {                                                          \
	                while ( ( SSP1CON2 & 0x1F ) | ( SSP1STATbits.R_W ) )   \
	                   continue;                                           \
                    }

    extern void I2C1Init(unsigned char i2cMode);
    extern __inline unsigned char I2C1DataRdy( void );
    extern __inline unsigned char I2C1MasterRead( void );
    extern signed char I2C1MasterWrite( unsigned char data_out );
    extern signed char I2C1SlaveWrite( unsigned char data_out );
    extern signed char I2C1MasterReadBytes( unsigned char *rdptr, unsigned char length );
    extern signed char I2C1MasterWriteBytes( unsigned char *wrptr , unsigned char Length);
    extern signed char I2C1SlaveWriteBytes( unsigned char *wrptr , unsigned char Length);




#ifdef	__cplusplus
}
#endif

#endif	/* PIC18_I2C_H */

